package com.example.mine_platform.controller;

import com.example.mine_platform.commom.Result;
import com.example.mine_platform.pojo.dto.DeviceDTO;
import com.example.mine_platform.pojo.dto.DeviceNewDTO;
import com.example.mine_platform.pojo.entities.Devices;
import com.example.mine_platform.pojo.vo.DeviceVO;
import com.example.mine_platform.service.DeviceService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class DevicesController {
    @Resource
    private DeviceService deviceService;

    @GetMapping("/api/allDevices")
    public Result getAllDevices() {
        List<DeviceVO> deviceVOList = deviceService.getAllDevices();
        return Result.success(deviceVOList);
    }
    @GetMapping("/api/device/{id}")
    public Result getDeviceDetail(@PathVariable Integer id){
        Devices devices = deviceService.getDevicesById(id);
        return Result.success(devices);
    }
    @PostMapping("/api/device")
    public Result insertDevice(@RequestBody DeviceNewDTO deviceNewDTO){
        Result result = deviceService.insertDevice(deviceNewDTO);
        return result;
    }
    @PutMapping("/api/device")
    public Result updateDevice(@RequestBody DeviceDTO deviceDTO){
        Result result = deviceService.updateDevice(deviceDTO);
        return result;
    }
    @DeleteMapping("/api/device/{id}")
    public Result deleteDevice(@PathVariable Integer id){
        Result result = deviceService.deleteDevice(id);
        return result;
    }
}
